<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<html>
	<head>


		<title>申领电子面单</title>
<script type="text/javascript">
   	var datatable_content ;
	$(function(){
		initTable();
	});
  	function initTable(){
			datatable_content = $("#contentTable").dataTable({
			   "bServerSide":true,
	           "sAjaxSource":'${ctx}/v2/logistics/findLogistics',
	           "fnServerData": callback,
	           "bFilter": false,
	           "bSort": false,
	           "sZeroRecords": "查询无记录！",
	           "bProcessing": true, 
	           "oLanguage": {
	               "sUrl": '${ctx}/static/v2/js/plugins/datatables/cn.txt'
	            },
	             "aoColumns":[
	             	 {"mData": "fullName"},
	             	 {"mData": "groupName"},
	             	 {"mData": "unuse"},
	             ],
	             
	             "aoColumnDefs":[
	            	
	             ]
			});
		}
		function callback( sSource, aoData, fnCallback ) {
		 aoData.push( { "name": "search_LIKE_companyCode", "value": $("#search_LIKE_companyCode").val()},
		 			  { "name": "search_LIKE_areaGroupCode", "value": $("#search_LIKE_areaGroupCode").val()});  
			 //查询参数
		   $.ajax({ 
		       "type": "post",
		       "contentType": "application/json", 
		       "url": sSource,    
		       "dataType": "json",   
		       "data": JSON.stringify(aoData),
		       "success": fnCallback  
		   });    
		}
		function query(){
			datatable_content.fnDestroy();
			initTable();
		}
	
	function ajaxMailNoRequest(){
        var areaGroupCode=$("#search_LIKE_areaGroupCode").val();
        var companyCode=$("#search_LIKE_companyCode").val();
        
        if(areaGroupCode==""||companyCode==""){
        	alert("仓库和快递公司不能为空！");
        	return;
        }
        showBg();
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/logistics/ajaxMailNoRequest',
			data : 'areaGroupCode=' + areaGroupCode+'&companyCode='+companyCode,
			dataType : 'json',
			success : function(data) {
				if (data.status == "1") {
					jAlert("申领了"+data.content+"个号段");
					closeBg();
				} else  {
					jAlert(data.content);
					closeBg();
				}
			},
			error : function() {
				jAlert("加载出错！！！");
				closeBg();
			}
		});
	}
	function AjaxAddMailNo(){
		showBg();
		var areaGroupCode = $("#areaGroupCode").val();
		var companyCode = $("#companyCode").val();
		var from_number = $("#from_number").val();
		var to_number = $("#to_number").val();
		var sequence = $("#sequence").val();
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/logistics/addMailNo',
			data : {
				areaGroupCode : areaGroupCode,
				companyCode : companyCode,
				from_number : from_number,
				to_number : to_number,
				sequence : sequence
			},
			dataType : 'json', 
			success : function(data) {
				if (data.status == "1") {
				    jAlert("添加了"+data.content+"个号段");
					closeBg();
				} else  {
					jAlert(data.content);
					closeBg();
				}
			},
			error : function() {
				jAlert("加载出错！！！");
				closeBg();
			}
		});
	}
</script>
	</head>

	<body>
	<div id="fullbg"></div>
<div id="dialog">
	<div>
		<img src="${ctx }/static/022.gif"></img>
	</div>
</div>
	<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Primary box -->
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">运单号申领</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	      <div class="form-group row">
						<div class="col-sm-3">
							<div class="input-group col-sm-12">
	  		    <label class="input-group-text">仓库:</label>
				<select class="form-control" id="search_LIKE_areaGroupCode" name="search_LIKE_areaGroupCode" onchange="query();">
						<option value=""></option>
					<c:forEach items="${warehouseList}" var="w">
						<option value="${w.groupCode}" <c:if test="${groupCode eq  w.groupCode}">selected</c:if>> ${w.groupName} </option>
					</c:forEach>
				</select>
				</div>
			 	</div>
			 	
			 	<div class="col-sm-3">
							<div class="input-group col-sm-12">
		     	<label class="input-group-text">快递公司:</label>
				<select class="form-control" id="search_LIKE_companyCode" name="search_LIKE_companyCode" onchange="query();">
						<option value=""></option>
					<c:forEach items="${company}" var="o">
						<option value="${o.companyCode}" <c:if test="${companyCode eq  o.companyCode}">selected</c:if>> ${o.companyName} </option>
					</c:forEach>
				</select>
				</div>
			 	</div>
			 	
			 	<div class="col-sm-3">
							<div class="input-group col-sm-12">
				<a class="btn btn-primary" role="button" style="margin-left: 10px;" onclick="query()">搜索</a>
				<a class="btn btn-primary" role="button" style="margin-left: 10px;" onclick="ajaxMailNoRequest()">开始申领运单</a>
				<!-- <a href="#addMailNo" role="button" data-toggle="modal" class="btn btn-primary"  onclick="" style="margin-left: 20px;">添加面单</a> -->
				</div>
			 	</div>
		 </div>
    </div>
    </div>
    </div>
    </div>
    
    <div class="form-group row">
		<div class="col-md-12">
			<div class="box box-solid box-primary">
				<div class="box-header">
					<i class="fa fa-list"></i>
					<h3 class="box-title">查询结果</h3>
					<div class="box-tools pull-right">
						<button class="btn btn-primary btn-sm" data-widget="collapse">
							<i class="fa fa-minus"></i>
						</button>
					</div>
				</div>
				<div class="box-body">
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<th>快递公司</th>
				<th>仓库</th>
				<th>可用数量</th>
			</tr>
		</thead>
		<tbody>
			
		</tbody>
	</table>
	</div>
		</div>
		</div>
		</div>
    </section>
    
    
    
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" id="addMailNo" >    
    <div class="modal-dialog" style="width:600px; height:500px;">
    <div class="modal-content">+
    <form id="inputForm" action="${ctx}/v2/logistics/addMailNo" method="post" class="form-horizontal">
		<fieldset>
		<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal"
					aria-hidden="true">
					×
				</button>
				<h3 id="myModalLabel">

				</h3>
				<span id="messageLable"></span>
			</div>
			<div class="form-group">
				<label for="" class="col-sm-3 control-label">快递公司：</label>
				<div class="col-sm-6">
					<select class="form-control" id="companyCode" name="companyCode">
					<c:forEach items="${company}" var="o">
						<option value="${o.companyCode}" <c:if test="${companyCode eq  o.companyCode}">selected</c:if>> ${o.companyName} </option>
					</c:forEach>
				</select>
				</div>
			</div>	
			<div class="form-group">
				<label for="" class="col-sm-3 control-label">仓库:</label>
				<div class="col-sm-6">
					<select class="form-control" id="areaGroupCode" name="areaGroupCode">
					<c:forEach items="${warehouseList}" var="warehouse">
				       <option value="${warehouse.groupCode}" 
				       <c:if test="${warehouseCode eq warehouse.groupCode }">selected=selected</c:if>
				       >${warehouse.groupName}</option>
				     </c:forEach>
				     </select>
				</div>
			</div>	
			<div class="form-group">
				<label for="from_number" class="col-sm-3 control-label">电子面单起始号:</label>
				<div class="col-sm-6">
					<input type="text" id="from_number" name="from_number"  value="" class="form-control input-large required" minlength="1"/>
				</div>
			</div>	
			<div class="form-group">
				<label for="to_number" class="col-sm-3 control-label">电子面单结束号:</label>
				<div class="col-sm-6">
					<input type="text" id="to_number" name="to_number"  value="" class="form-control input-large required" minlength="1"/>
				</div>
			</div>	
			<div class="form-group">
				<label for="sequence" class="col-sm-3 control-label">序列号:</label>
				<div class="col-sm-6">
					<input type="text" id="sequence" name="sequence"  value="" class="form-control input-large required" minlength="1"/>
				</div>
			</div>
			<div class="modal-footer bg-gray">
				<a class="btn btn-primary" data-dismiss="modal" aria-hidden="true" onclick="AjaxAddMailNo()"> 确认 </a>
				<a class="btn btn-info" data-dismiss="modal" aria-hidden="true"> 关闭 </a>
			</div>
		</fieldset>+
		</form>
		</div>
		</div>
		</div>
	</body>
</html>
